﻿using System;
using System.Diagnostics;
using System.Windows.Forms;
using ReportWizard.Entities;
using ReportWizard.Helpers;

namespace ReportWizard.Controls
{
    public partial class PhotoInfo : UserControl
    {
        public ReportImageFile ImageFileInfo { get; set; }

        public new event EventHandler Click;

        public PhotoInfo()
        {
            InitializeComponent();
        }

        public PhotoInfo(ReportImageFile rif)
        {
            InitializeComponent();

            ImageFileInfo = rif;

            if (rif != null)
            {
                checkPhotoName.Text = rif.FileName;
                tbPhotoDescription.Text = rif.Description;
                pbPhotoThumb.ImageLocation = rif.FilePath;
                checkPhotoName.Checked = rif.Checked;
            }
        }

        private void tbPhotoDescription_TextChanged(object sender, EventArgs e)
        {
            ImageFileInfo.Description = tbPhotoDescription.Text.Trim();
        }

        private void checkPhotoName_CheckedChanged(object sender, EventArgs e)
        {
            ImageFileInfo.Checked = checkPhotoName.Checked;
        }

        private void checkPhotoName_Click(object sender, EventArgs e)
        {
            if (Click != null)
            {
                Click(this, e);
            }
        }

        private void pbPhotoThumb_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                Process.Start(pbPhotoThumb.ImageLocation);
            }
            catch (Exception ex)
            {
                Logger.WriteLog(ex);
            }
        }
    }
}
